<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="名称" prop="name">
        <el-input
          v-model="queryParams.params.name"
          placeholder="请输入名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产编号" prop="code">
        <el-input
          v-model="queryParams.params.code"
          placeholder="请输入生产编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销售编号" prop="salecode">
        <el-input
          v-model="queryParams.params.salecode"
          placeholder="请输入销售编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料id" prop="invid">
        <el-input
          v-model="queryParams.params.invid"
          placeholder="请输入物料id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日期" prop="date">
        <el-date-picker clearable
          v-model="queryParams.params.date"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="备注" prop="memo">
        <el-input
          v-model="queryParams.params.memo"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门id" prop="deptid">
        <el-input
          v-model="queryParams.params.deptid"
          placeholder="请输入部门id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleFilter">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetSearch">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleCreate"
          v-hasPermi="['business:produce:save']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:produce:save']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDeletes"
          v-hasPermi="['business:produce:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="exportExcel"
          v-hasPermi="['business:produce:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="handleFilter"></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="list"
      :height="tableHeight"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="" align="center" prop="id" />
      <el-table-column label="名称" align="center" prop="name" />
      <el-table-column label="部门状态" align="center" prop="status" />
      <el-table-column label="生产编号" align="center" prop="code" />
      <el-table-column label="销售编号" align="center" prop="salecode" />
      <el-table-column label="物料id" align="center" prop="invid" />
      <el-table-column label="日期" align="center" prop="date" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.date, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="memo" />
      <el-table-column label="部门id" align="center" prop="deptid" />
      <el-table-column
        label="操作"
        align="center"
        fixed="right"
        min-width="140"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:produce:save']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:produce:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="fetchData"
    />

    <!--编辑-->
    <Edit
      :visible.sync="dialogFormVisible"
      :dialogStatus="dialogStatus"
      :form="form"
      @success="saveSuccess"
    ></Edit>
  </div>
</template>

<script>
import { produce } from "@/api/business/produce";
import Edit from "./components/edit";
import { listMixin } from "@/mixins/list"

export default {
  name: "Produce",
  mixins: [ listMixin ],
  components: { Edit },
  data() {
    return {

    };
  },
  created() {
    //获取列表数据
    this.fetchData();
  },
  methods: {
    //调用list接口
    callList(queryParams) {
      return new Promise(function(resolve, reject) {
        produce.list(queryParams).then((res) => {
          resolve(res);
        }).catch((error) => {
          reject(error)
        });
      });
    },
    //调用findById接口
    callFindById(id) {
      return new Promise(function(resolve, reject) {
        produce.findById(id).then((res) => {
          resolve(res);
        }).catch((error) => {
          reject(error)
        });
      });
    },
    //调用delete接口
    callDelete(id) {
      return new Promise(function(resolve, reject) {
        produce.del(id).then((res) => {
          resolve(res);
        }).catch((error) => {
          reject(error)
        });
      });
    },
    //调用batchDel接口
    callDeletes(ids) {
      return new Promise(function(resolve, reject) {
        produce.batchDel(ids).then((res) => {
          resolve(res);
        }).catch((error) => {
          reject(error)
        });
      });
    },
    //调用exportExcel接口
    callExport(queryParams) {
      let _this = this;
      return new Promise(function(resolve, reject) {
        _this.download('business/produce/export', {
              ...queryParams
        }, `生产管理_`+new Date().getTime()+`.xlsx`)
      });
    }
  }
};
</script>

<style lang="scss" scoped>

</style>
